package com.qf.test01.dao.impl;

import com.qf.test01.dao.UserDao;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class UserDaoImplCache implements UserDao {
    private String name;
    private Integer age;
    private String filePath;
    private BufferedReader bufferedReader;

    public UserDaoImplCache() {
        System.out.println("调用了UserDaoImplCache无参构造函数");
    }

    public void init() {
        System.out.println("初始化");
        if (this.filePath != null) {
            try {
                this.bufferedReader = new BufferedReader(new FileReader(filePath));
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public void close() {
        System.out.println("销毁了");
        try {
            this.bufferedReader.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("setName");
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        System.out.println("setAge");
        this.age = age;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        System.out.println("setFilePath");
        this.filePath = filePath;
    }

    @Override
    public void helloUser() {
        System.out.println("UserDaoImplCache:hello user");
    }
}
